【例子介绍】用Delphi XE8开发iOS苹果和Android安卓移动应用
【相关图片】
【源码结构】
C ONTENTS
Mobile Tutorials: Mobile Application Development (iOS and Android) ................. 11
Setup ................................................................................................................................. 11
Using Basic User Interface Elements ............................................................................. 12
Using Device Functionality ............................................................................................ 14
Using Backend as a Service .......................................................................................... 15
Accessing a Database .................................................................................................. 15
See Also ......................................................................................................................... 16
Mobile Tutorial: Set Up Your Development Environment on the Mac (iOS) .......... 17
Requirements on the Mac and iOS .......................................................................... 17
Steps to Configure Your Mac to Run Your iOS Application .................................. 18
Step 1: Install the Platform Assistant ...................................................................... 18
Step 2: Run the Platform Assistant ......................................................................... 19
Step 3: Install Xcode on the Mac .......................................................................... 20
Next Steps ................................................................................................................. 21
Additional Steps to Configure Your Mac to Run Your iOS Application on Your iOS
Device............................................................................................................................... 22
Step 1: Make Sure that the Xcode Command Line Tools Are Installed on Your
Mac ............................................................................................................................... 22
Step 2: Sign Up for a Developer Account ............................................................... 24
Step 3: Request, Download and Install Your Development Certificate ............. 24
Request, Download and Install Your Certificate ................................................ 25
Step 4: Register Your Device for Deployment ......................................................... 26
Step 5: Create and Install a Provisioning Profile ..................................................... 27
See Also ......................................................................................................................... 29
Mobile Tutorial: Set Up Your Development Environment on Windows PC (iOS) ... 30
Setting Up Your RAD Studio Environment ................................................................ 31
Create a Connection Profile for the Mac ........................................................... 31
Add an SDK to the Development System for the iOS Device Connected to
the Mac ..................................................................................................................... 34
See Also ......................................................................................................................... 36
Mobile Tutorial: Set Up Your Development Environment on Windows PC
(Android) .......................................................................................................................... 37
Setting Up Your RAD Studio Environment ................................................................ 37
Android Development Tools Are Installed with RAD Studio .............................. 38
Adding Your Android SDK in Tools Options > SDK Manager ............................. 40
Installing the USB Driver for Your Android Device (Required) ............................... 44
See Also ......................................................................................................................... 47
Mobile Tutorial: Creating an Application for Mobile Platforms (iOS and Android)
........................................................................................................................................... 48
Before You Start ........................................................................................................... 48
Step 1: Create a New FireMonkey Application for Android or iOS ..................... 49
Embarcadero Technologies 4
Step 2: Select a Style ................................................................................................... 50
Step 3: Place Components on the Multi-Device Form .......................................... 50
Step 4: Adding Views to Your Project....................................................................... 54
Step 5: Write an Event Handler for a Button Click by the User ............................. 54
Step 6: Test Your Mobile Application ........................................................................ 56
Test Your Android Application on the Android Device ..................................... 57
Test Your iOS Application ....................................................................................... 58
See Also ......................................................................................................................... 60
Mobile Tutorial: Using a Button Component with Different Styles (iOS and
Android) ............................................................................................................................ 61
Buttons in Mobile Platforms ........................................................................................ 61
Define the Look and Feel for a Button Component .............................................. 62
Using TintColor and IconTintColor on Buttons ..................................................... 63
Using Styled and Colored Buttons on Target Platforms ..................................... 65
Placing an Image over a Button ........................................................................... 65
Create a Segmented Control Using Button Components ................................... 66
Create a Scope Bar on a Toolbar Component ..................................................... 68
See Also ......................................................................................................................... 69
Mobile Tutorial: Using a Calendar Component to Pick a Date (iOS and Android)
........................................................................................................................................... 70
Calendar in Mobile Platforms .................................................................................... 70
Implementing an Event Handler for User Changes to the Date .......................... 72
See Also ......................................................................................................................... 74
Mobile Tutorial: Using Combo Box Components to Pick Items from a List (iOS and
Android) ............................................................................................................................ 75
Implementing a Picker in Multi-Device Applications ............................................. 75
Building a List of Items Using Code ........................................................................... 78
Displaying a Specific Item .......................................................................................... 78
Implementing an Event Handler for the User's Selection ...................................... 80
See Also ......................................................................................................................... 81
Mobile Tutorial: Using a Map Component to Work with Maps (iOS and Android)
........................................................................................................................................... 82
Basic Features of the TMapView Component ........................................................ 83
Creating a Sample Application ................................................................................ 83
Configuring Android Applications to Use the TMapView component ........... 83
Designing the User Interface .................................................................................. 83
Running the Sample Application .............................................................................. 88
See Also ......................................................................................................................... 90
Configuring Android Applications to Use Google Maps .......................................... 91
Getting the Google Maps API key ........................................................................... 91
Retrieving Your Application Certificate ............................................................... 91
Creating an API Project in the Google APIs Console ........................................ 92
Requesting a Maps API Key ................................................................................... 93
Configuring Specific Project Options ....................................................................... 93
Embarcadero Technologies 5
See Also ......................................................................................................................... 97
Mobile Tutorial: Using a MultiView Component to Display Alternate Views of
Information (iOS and Android)...................................................................................... 98
About the TMultiView Component ........................................................................... 98
Master Pane Presentation Modes ......................................................................... 99
Designing the User Interface ................................................................................... 103
Designing the Master Pane .................................................................................. 104
Designing the Detail Pane.................................................................................... 104
Implementing the Camera Buttons Functionality ............................................ 105
Setting the TMultiView Component Properties ................................................. 109
Running the Example Application .......................................................................... 109
Mobile Product Samples that Use TMultiView ....................................................... 110
See Also ....................................................................................................................... 111
Mobile Tutorial: Using the Web Browser Component (iOS and Android) ............ 112
Design the User Interface ......................................................................................... 113
Write an Event Handler to Open a Web Page when the User Changes the URL
in the Edit Control ...................................................................................................... 115
Implement a Common Method to Open a Web Page .................................. 116
Implement an Event Handler for the OnChange Event ................................. 117
Implement an Event Handler for the Back Button ........................................... 118
Selecting the Proper Virtual Keyboard for the Web Browser Application ....... 119
WebBrowser Mobile Code Snippet ........................................................................ 120
See Also ....................................................................................................................... 121
Mobile Tutorial: Using Tab Components to Display Pages (iOS and Android) .... 122
Using the Native Style for Tabs on iOS and Android ........................................ 122
Designing Tab Pages Using the Form Designer .................................................... 123
Comparing the Tab Settings on iOS and Android ............................................ 127
Using Custom Multi-Resolution Icons for Your Tabs .............................................. 133
Displaying Multi-Resolution Custom Icons on Tabs ........................................... 134
Using a Single-Resolution Bitmap for a Custom Icon ....................................... 137
Defining Controls within a TabControl ................................................................... 139
Changing the Page at Run Time ............................................................................ 141
By the User Tapping the Tab ................................................................................ 141
By Actions and an ActionList ............................................................................... 141
By Source Code ..................................................................................................... 146
See Also ....................................................................................................................... 147
Mobile Tutorial: Using LiveBindings to Populate a ListView (iOS and Android) ... 148
Step 1: Creating the Project .................................................................................... 148
Step 2: Adding Fields ................................................................................................ 150
Step 3: Creating LiveBindings .................................................................................. 151
Step 4: Adding More Fields (Bitmaps, Currency) .................................................. 154
Step 5: Adding the onButtonClick Event Handler ................................................ 155
The Results ................................................................................................................... 156
See Also ....................................................................................................................... 157
Embarcadero Technologies 6
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and
Android) .......................................................................................................................... 158
Using ListBox Components to Display a Table View in Mobile Platforms .......... 158
Plain List ................................................................................................................... 159
Grouped List ........................................................................................................... 160
Search Box .............................................................................................................. 161
Create Items on the ListBox Component .............................................................. 161
Add a Header ........................................................................................................ 164
Add a Group Header/Footer to the List ............................................................. 165
Show List Items as Separate Grouped Items ..................................................... 166
Add a Check Box or Other Accessory to a ListBox Item ................................. 167
Add an Icon to a ListBox Item .............................................................................. 167
Add Detail Information to an Item ...................................................................... 168
Running Your Application .................................................................................... 168
Create Your ListBox Application ............................................................................. 168
Add Items to a ListBox from Your Code ............................................................. 169
Create an Overflow Menu ................................................................................... 172
Creating the Event Handler for the Overflow Button ...................................... 174
Add a Search Box .................................................................................................. 175
Running Your Application .................................................................................... 176
See Also ....................................................................................................................... 177
Mobile Tutorial: Using LiveBindings to Populate a ListBox in Mobile Applications
(iOS and Android) ......................................................................................................... 178
Step 1: Creating the Project .................................................................................... 178
Step 2: Creating the LiveBindings ........................................................................... 181
The Results ................................................................................................................... 183
See Also ....................................................................................................................... 184
Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS
and Android) ................................................................................................................. 185
Every FireMonkey Component Can Have an Owner, a Parent, and Children
...................................................................................................................................... 185
Using Common Layout-Related Properties of a FireMonkey Component ...... 185
Using the Align Property........................................................................................ 185
Using the Margins Property ................................................................................... 187
Using the Padding Property ................................................................................. 187
Using the Anchors Property .................................................................................. 188
Using the TLayout Component ............................................................................... 189
See Also ....................................................................................................................... 190
Mobile Tutorial: Taking and Sharing a Picture, and Sharing Text (iOS and Android)
......................................................................................................................................... 191
Topics .......................................................................................................................... 195
See Also ....................................................................................................................... 195
Mobile Tutorial: Using Location Sensors (iOS and Android) .................................... 196
Design the User Interface ......................................................................................... 197
Embarcadero Technologies 7
The Location Sensor .................................................................................................. 199
Read Location Information (Latitude, Longitude) from the LocationSensor
Component ................................................................................................................ 199
Show the Current Location Using Google Maps via a TWebBrowser
Component ................................................................................................................ 201
Use Reverse Geocoding .......................................................................................... 202
Show a Readable Address in the ListBox Component ........................................ 205
Describing Why Your Application Needs the User Location .............................. 206
See Also ....................................................................................................................... 206
Mobile Tutorial: Using Notifications (iOS and Android)............................................ 207
Three Basic Notification or Alert Styles ................................................................... 207
Notification Banner on Mobile Devices ............................................................. 207
Alert Dialogs: iOS Badge Number and Android Notification Number .......... 208
Notification Center on Mobile Devices ................................................................. 208
Access the Notification Service .............................................................................. 209
Add FMLocalNotificationPermission (iOS 8 Only) ................................................. 210
Set the Icon Badge Number and Notification Number from Code ................. 210
Schedule Notification ............................................................................................... 212
Repeat a Notification Message .............................................................................. 214
Update or Cancel a Scheduled or Repeated Notification Message .............. 216
Present the Notification Message Immediately ................................................... 217
Customizing the Notification Sound ....................................................................... 219
Notification Banner or Notification Alert ................................................................ 223
Add Action to the Notification Alert (iOS Only).................................................... 224
Add Action to Notifications ..................................................................................... 226
Running the Application .......................................................................................... 227
See Also ....................................................................................................................... 227
Mobile Tutorial: Using Remote Notifications (iOS and Android) ............................ 228
Remote Push Notification ........................................................................................ 228
REST BAAS framework ............................................................................................... 229
Topics in this Mobile Tutorial ..................................................................................... 229
See Also ....................................................................................................................... 229
Code Samples........................................................................................................ 229
Multi-Device Application to Receive Push Notifications ........................................ 230
Design and Set Up the User Interface .................................................................... 230
Creating the Event Handlers ................................................................................... 235
Android Settings......................................................................................................... 238
Project Settings ....................................................................................................... 238
iOS Settings ................................................................................................................. 239
Project Settings ....................................................................................................... 239
Running Your Application on a Mobile Device .................................................... 239
See Also ....................................................................................................................... 243
Code Samples........................................................................................................ 243
Mobile Tutorial: Using the Phone Dialer on Mobile Devices (iOS and Android) .. 244
Embarcadero Technologies 8
About the Phone Dialer Services on Mobile Devices .......................................... 244
Accessing the Phone Dialer Services ..................................................................... 244
Designing the User Interface ................................................................................... 246
Getting the Carrier Properties ................................................................................. 246
Running the Application....................................................................................... 247
Making a Call ............................................................................................................. 248
Detecting the Call State Changes ......................................................................... 250
Implementing the OnCallStateChanged Event Handler ................................ 251
See Also ....................................................................................................................... 255
Mobile Tutorial: Using BaaS for Backend Storage (iOS and Android) ................... 256
Getting Your App Ready in Kinvey and Parse ...................................................... 257
Design and Set Up of the User Interface ............................................................... 257
Adding the Backend Components ........................................................................ 258
Creating and Storing Objects ................................................................................. 260
Deleting Objects........................................................................................................ 261
Retrieving Objects ..................................................................................................... 263
Running Your Application ........................................................................................ 267
See Also ....................................................................................................................... 268
Code Samples........................................................................................................ 268
Mobile Tutorial: Using InterBase ToGo with dbExpress (iOS and Android) ........... 269
Using dbExpress to Connect to the Database ..................................................... 270
Design and Set Up the User Interface .................................................................... 271
Connecting to the Data .......................................................................................... 272
Deploying Your Application to Mobile .................................................................. 275
Deploy InterBase ToGo, dbExpress Driver, and the Database File to Mobile
.................................................................................................................................. 275
Modify Your Code to Connect to a Local Database File on Mobile ............ 278
Run Your Application on a Simulator or on a Mobile Device ............................ 280
Troubleshooting ......................................................................................................... 281
InterBase Issues ....................................................................................................... 281
Exception Handling Issues .................................................................................... 281
See Also ....................................................................................................................... 282
Mobile Tutorial: Using InterBase ToGo with FireDAC (iOS and Android) ............... 283
Using FireDAC to Connect to the Database ........................................................ 285
Design and Set Up the User Interface .................................................................... 285
Connecting to the Data .......................................................................................... 286
Deploying your Application to Mobile ................................................................... 290
Deploying InterBase ToGo Required Files and the Database File to Mobile290
Run Your Application on a Simulator or on a Mobile Device ............................ 293
Troubleshooting ......................................................................................................... 294
InterBase Issues ....................................................................................................... 294
Exception Handling Issues .................................................................................... 294
See Also ....................................................................................................................... 295
Mobile Tutorial: Using dbExpress and SQLite (iOS and Android) ........................... 296
Embarcadero Technologies 9
Using dbExpress to Connect to the Database ..................................................... 297
Creating the Database in the Windows Environment for Development
Purposes ...................................................................................................................... 297
Create the Database in the Data Explorer ....................................................... 297
Create Table on DataExplorer ............................................................................ 299
Design and Set Up the User Interface .................................................................... 300
Connecting to the Data .......................................................................................... 302
Creating the Event Handler to Make the Delete Button Visible When the User
Selects an Item from the List .................................................................................... 304
Creating the Event Handler for the Add Button to Add an Entry to the List .... 305
Creating the Event Handler for the Delete Button to Remove an Entry from the
List ................................................................................................................................ 309
Setting Up Your Database Deployment for Mobile Platforms ............................ 311
Add and Configure Your Database File in the Deployment Manager ........ 311
Modifying Your Code to Connect to a Local Database File on Mobile
Platforms ..................................................................................................................... 312
Specifying the Location of the SQLite Database on the Mobile Device ..... 312
Creating a Table if None Exists ............................................................................ 313
Running Your Application on a Mobile Device .................................................... 314
See Also ....................................................................................................................... 316
Mobile Tutorial: Using FireDAC and SQLite (iOS and Android)............................... 317
Using FireDAC to Connect to the Database ........................................................ 318
Creating the Database using FireDAC framework .............................................. 318
Design and Set Up the User Interface .................................................................... 320
Using the LiveBindings Wizard .................................................................................. 322
Add the LiveBinding components ...................................................................... 322
Connecting to the Data ....................................................................................... 324
Displaying ShopItem in the ListView .................................................................... 326
Creating the Event Handler to Make the Delete Button Visible When the User
Selects an Item from the List .................................................................................... 326
Creating the Event Handler for the Add Button to Add an Entry to the List .... 327
Creating the Event Handler for the Delete Button to Remove an Entry from the
List ................................................................................................................................ 331
Preparing Your Application for Run Time ............................................................... 333
Setting Up Your Database Deployment for mobile ............................................. 333
Add and Configure Your Database File in the Deployment Manager ........ 333
Modifying Your Code to Connect to a Local Database File on mobile .......... 334
Specifying the Location of the SQLite Database on the Mobile Device ..... 334
Creating a Table if None Exists ............................................................................ 335
Running Your Application on a Simulator or on a Mobile Device ..................... 336
See Also ....................................................................................................................... 337
Mobile Tutorial: Connecting to an Enterprise Database from a Mobile Client (iOS
and Android) ................................................................................................................. 338
Creating the Middle Tier, a DataSnap Server ....................................................... 339
Embarcadero Technologies 10
Create a DataSnap Server VCL Application .................................................... 339
Define a DataSet on the DataSnap Server ....................................................... 341
Expose the DataSet from the DataSnap Server ............................................... 343
Run the DataSnap Server ..................................................................................... 344
Creating a Mobile Application that Connects to the DataSnap Server ......... 345
Deploy the MIDAS Library to iOS Simulator ........................................................... 348
Run Your Application on the mobile platform ...................................................... 348
See Also ....................................................................................................................... 349
Mobile Tutorial: Using FireDAC in Mobile Applications (iOS and Android) .......... 350
Using FireDAC to Connect to the Database ........................................................ 350
Design and Set Up the User Interface .................................................................... 351
Using the LiveBindings Wizard .................................................................................. 352
Add the LiveBinding components ...................................................................... 352
Add the ListView component .............................................................................. 354
Using the LiveBindings Wizard .................................................................................. 356
Preparing Your Application for Run Time ............................................................... 357
Setting Up Your Database Deployment for mobile ............................................. 357
Add and Configure Your Database File in the Deployment Manager ........ 357
Modifying Your Code to Connect to a Local Database File on Mobile .......... 358
Specifying the Location of the SQLite Database on the Mobile Device ..... 358
Running Your Application on the Simulator or on the Mobile Device .............. 360
See Also ....................................................................................................................... 361
Mobile Tutorials: Table of Components Used ........................................................... 362
评论